#include <iostream>
using namespace std;

const int N=2e5+10;
int dp[N];
int n;



int main()
{
	int ret=-1e5;
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		int x; cin>>x;
		if(dp[i-1] > 0) dp[i]=dp[i-1]+x;
		else dp[i]=x;
		ret=max(ret, dp[i]);
	}
	cout<<ret<<endl;
	return 0;
}
